package com.ecube.sql;

import com.ecube.mqtt.MqttUtils;
import com.ecube.mqtt.PushCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class BBOXStateMax {

    public static void main(String[] args) {
        SendTBbox s0 = new SendTBbox();
        SendTBbox s1 = new SendTBbox();
        SendTBbox s2 = new SendTBbox();
        SendTBbox s3 = new SendTBbox();
        SendTBbox s4 = new SendTBbox();
        SendTBbox s5 = new SendTBbox();
        SendTBbox s6 = new SendTBbox();
        SendTBbox s7 = new SendTBbox();
        SendTBbox s8 = new SendTBbox();
        SendTBbox s9 = new SendTBbox();
        s0.start();
        s1.start();
        s2.start();
        s3.start();
        s4.start();
        s5.start();
        s6.start();
        s7.start();
        s8.start();
        s9.start();
    }

}

class SendTBbox extends Thread{
    public void run() {
        for (int i = 0; i <10; i++){
            sendBBOX();
        }

    }
    public static void sendBBOX(){
        Random random = new Random();
        int min = 10000000;
        int max = 99999999;

        int battery = random.nextInt(max - min +1) + min;
        sendLoginMQTT("UAT", "40041109998843" + battery, "4004"+ battery);
        sendHeartMQTT("UAT", "40041109998843" + battery,"YH000000000011111", "4004" + battery);

    }
    public static void sendLoginMQTT(String env, String externalCode, String batteryCode) {
        String pubTopic = "200010001/" + externalCode + "/loginv2";
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String content = " {\n" +
                "\"dataTime\":\"" + dateFormat.format(date) + "\",\n" +
                "\"loginNo\":1,\n" +
                "\"iccid\":\"" + externalCode + "\",\n" +
                "\"rechargeEnergyStorageSubsystemNum\":10,\n" +
                "\"rechargeEnergyStorageSubsystemCodeLength\":12,\n" +
                "\"rechargeEnergyStorageSubsystemCode\":\"" + batteryCode + "\",\n" +
                "\"hdVersion\":\"1.0.2\",\n" +
                "\"softwareVersion\":\"1.0.2.4\",\n" +
                "\"protocolVersion\":\"1.1.0\",\n" +
                "\"firmwareVersion\":\"AG35CEVDR08A02T4G_OCPU1[Feb23202210:00:00]\"\n" +
                "}";


        sendMQTT(env, pubTopic, content, batteryCode);

    }

    public static void sendHeartMQTT(String env, String externalCode, String vin, String batteryCode) {
        String pubTopic = "200010001/" + externalCode + "/realTimeDatav2";
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Random random = new Random();
        int longitudemin = 83282617;
        int longitudemax = 118224572;

        int longitude = random.nextInt(longitudemax - longitudemin +1) + longitudemin;


        int latitudemin = 24181484;
        int latitudemax = 42117275;

        int latitude = random.nextInt(latitudemax - latitudemin +1) + latitudemin;

        String content = "{\n" +
                "    \"tmsInfomation\": {\n" +
                "        \"softVersion\": 0,\n" +
                "        \"TMSSetTemperature\": 65,\n" +
                "        \"TMSDemandPower\": 0,\n" +
                "        \"TMSFaultCode\": 0,\n" +
                "        \"highPressureRequest\": 0,\n" +
                "        \"retureWaterTemperature\": 70,\n" +
                "        \"supplierCode\": 5,\n" +
                "        \"BMSRequestSettingMode\": 0,\n" +
                "        \"outletTemperature\": 69,\n" +
                "        \"BMSHighPressureVolRelayStatus\": 1,\n" +
                "        \"TMSWorkStatus\": 0,\n" +
                "        \"TMSHighVolRelayStatus\": 1,\n" +
                "        \"TMSFaultCodeLevel\": 0\n" +
                "    },\n" +
                "    \"carLocation\": {\n" +
                "        \"latitude\": " + latitude + ",\n" +
                "        \"positioningStatus\": 0,\n" +
                "        \"longitude\": " + longitude + "\n" +
                "    },\n" +
                "    \"rechargeStorageTemp\": {\n" +
                "        \"rechargeEnergyStorageSubsystemNum\": 16,\n" +
                "        \"rechargeEnergyStorageSubsystemTemperatureInfo\": [\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageTemperatureProbesNum\": 6,\n" +
                "                \"rechargeEnergyStorageSubsystemTemperatureValue\": [\n" +
                "                    66,\n" +
                "                    66,\n" +
                "                    66,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    66\n" +
                "                ],\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 1\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageTemperatureProbesNum\": 6,\n" +
                "                \"rechargeEnergyStorageSubsystemTemperatureValue\": [\n" +
                "                    66,\n" +
                "                    65,\n" +
                "                    64,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65\n" +
                "                ],\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 2\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageTemperatureProbesNum\": 6,\n" +
                "                \"rechargeEnergyStorageSubsystemTemperatureValue\": [\n" +
                "                    66,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    66\n" +
                "                ],\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 3\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageTemperatureProbesNum\": 6,\n" +
                "                \"rechargeEnergyStorageSubsystemTemperatureValue\": [\n" +
                "                    66,\n" +
                "                    66,\n" +
                "                    66,\n" +
                "                    66,\n" +
                "                    66,\n" +
                "                    67\n" +
                "                ],\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 4\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageTemperatureProbesNum\": 6,\n" +
                "                \"rechargeEnergyStorageSubsystemTemperatureValue\": [\n" +
                "                    66,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    66,\n" +
                "                    65,\n" +
                "                    66\n" +
                "                ],\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 5\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageTemperatureProbesNum\": 6,\n" +
                "                \"rechargeEnergyStorageSubsystemTemperatureValue\": [\n" +
                "                    65,\n" +
                "                    64,\n" +
                "                    64,\n" +
                "                    65,\n" +
                "                    64,\n" +
                "                    66\n" +
                "                ],\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 6\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageTemperatureProbesNum\": 6,\n" +
                "                \"rechargeEnergyStorageSubsystemTemperatureValue\": [\n" +
                "                    66,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    66\n" +
                "                ],\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 7\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageTemperatureProbesNum\": 6,\n" +
                "                \"rechargeEnergyStorageSubsystemTemperatureValue\": [\n" +
                "                    66,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    66\n" +
                "                ],\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 8\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageTemperatureProbesNum\": 6,\n" +
                "                \"rechargeEnergyStorageSubsystemTemperatureValue\": [\n" +
                "                    66,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    66\n" +
                "                ],\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 9\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageTemperatureProbesNum\": 6,\n" +
                "                \"rechargeEnergyStorageSubsystemTemperatureValue\": [\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    64,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    66\n" +
                "                ],\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 10\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageTemperatureProbesNum\": 6,\n" +
                "                \"rechargeEnergyStorageSubsystemTemperatureValue\": [\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65\n" +
                "                ],\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 11\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageTemperatureProbesNum\": 6,\n" +
                "                \"rechargeEnergyStorageSubsystemTemperatureValue\": [\n" +
                "                    66,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    66\n" +
                "                ],\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 12\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageTemperatureProbesNum\": 6,\n" +
                "                \"rechargeEnergyStorageSubsystemTemperatureValue\": [\n" +
                "                    66,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    66\n" +
                "                ],\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 13\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageTemperatureProbesNum\": 6,\n" +
                "                \"rechargeEnergyStorageSubsystemTemperatureValue\": [\n" +
                "                    65,\n" +
                "                    64,\n" +
                "                    64,\n" +
                "                    64,\n" +
                "                    65,\n" +
                "                    65\n" +
                "                ],\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 14\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageTemperatureProbesNum\": 6,\n" +
                "                \"rechargeEnergyStorageSubsystemTemperatureVal ue\": [\n" +
                "                    65,\n" +
                "                    64,\n" +
                "                    64,\n" +
                "                    64,\n" +
                "                    64,\n" +
                "                    65\n" +
                "                ],\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 15\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageTemperatureProbesNum\": 6,\n" +
                "                \"rechargeEnergyStorageSubsystemTemperatureValue\": [\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65,\n" +
                "                    65\n" +
                "                ],\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 16\n" +
                "            }\n" +
                "        ]\n" +
                "    },\n" +
                "    \"rechargeStorageVol\": {\n" +
                "        \"rechargeEnergyStorageSubsystemVolInfo\": [\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageDeviceCur\": 65535,\n" +
                "                \"startBatteryNo\": 1,\n" +
                "                \"totalNumberOfSingleBattery\": 24,\n" +
                "                \"singleBatteryNum\": 24,\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 1,\n" +
                "                \"rechargeEnergyStorageDeviceVol\": 65535,\n" +
                "                \"singleBatteryVolList\": [\n" +
                "                    3343,\n" +
                "                    3345,\n" +
                "                    3346,\n" +
                "                    3346,\n" +
                "                    3345,\n" +
                "                    3345,\n" +
                "                    3333,\n" +
                "                    3333,\n" +
                "                    3331,\n" +
                "                    3331,\n" +
                "                    3331,\n" +
                "                    3330,\n" +
                "                    3331,\n" +
                "                    3333,\n" +
                "                    3332,\n" +
                "                    3332,\n" +
                "                    3332,\n" +
                "                    3333,\n" +
                "                    3333,\n" +
                "                    3332,\n" +
                "                    3333,\n" +
                "                    3330,\n" +
                "                    3330,\n" +
                "                    3330\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageDeviceCur\": 65535,\n" +
                "                \"startBatteryNo\": 1,\n" +
                "                \"totalNumberOfSingleBattery\": 24,\n" +
                "                \"singleBatteryNum\": 24,\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 2,\n" +
                "                \"rechargeEnergyStorageDeviceVol\": 65535,\n" +
                "                \"singleBatteryVolList\": [\n" +
                "                    3331,\n" +
                "                    3331,\n" +
                "                    3332,\n" +
                "                    3332,\n" +
                "                    3332,\n" +
                "                    3332,\n" +
                "                    3332,\n" +
                "                    3332,\n" +
                "                    3330,\n" +
                "                    3330,\n" +
                "                    3330,\n" +
                "                    3330,\n" +
                "                    3331,\n" +
                "                    3332,\n" +
                "                    3332,\n" +
                "                    3332,\n" +
                "                    3332,\n" +
                "                    3332,\n" +
                "                    3332,\n" +
                "                    3332,\n" +
                "                    3330,\n" +
                "                    3328,\n" +
                "                    3328,\n" +
                "                    3327\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageDeviceCur\": 65535,\n" +
                "                \"startBatteryNo\": 1,\n" +
                "                \"totalNumberOfSingleBattery\": 24,\n" +
                "                \"singleBatteryNum\": 24,\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 3,\n" +
                "                \"rechargeEnergyStorageDeviceVol\": 65535,\n" +
                "                \"singleBatteryVolList\": [\n" +
                "                    3327,\n" +
                "                    3328,\n" +
                "                    3329,\n" +
                "                    3329,\n" +
                "                    3329,\n" +
                "                    3329,\n" +
                "                    3329,\n" +
                "                    3329,\n" +
                "                    3327,\n" +
                "                    3327,\n" +
                "                    3327,\n" +
                "                    3326,\n" +
                "                    3328,\n" +
                "                    3329,\n" +
                "                    3329,\n" +
                "                    3329,\n" +
                "                    3329,\n" +
                "                    3329,\n" +
                "                    3329,\n" +
                "                    3329,\n" +
                "                    3329,\n" +
                "                    3328,\n" +
                "                    3328,\n" +
                "                    3327\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageDeviceCur\": 65535,\n" +
                "                \"startBatteryNo\": 1,\n" +
                "                \"totalNumberOfSingleBattery\": 24,\n" +
                "                \"singleBatteryNum\": 24,\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 4,\n" +
                "                \"rechargeEnergyStorageDeviceVol\": 65535,\n" +
                "                \"singleBatteryVolList\": [\n" +
                "                    3328,\n" +
                "                    3329,\n" +
                "                    3329,\n" +
                "                    3330,\n" +
                "                    3329,\n" +
                "                    3329,\n" +
                "                    3330,\n" +
                "                    3330,\n" +
                "                    3328,\n" +
                "                    3328,\n" +
                "                    3328,\n" +
                "                    3328,\n" +
                "                    3342,\n" +
                "                    3343,\n" +
                "                    3344,\n" +
                "                    3343,\n" +
                "                    3344,\n" +
                "                    3343,\n" +
                "                    3344,\n" +
                "                    3343,\n" +
                "                    3342,\n" +
                "                    3341,\n" +
                "                    3343,\n" +
                "                    3340\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageDeviceCur\": 65535,\n" +
                "                \"startBatteryNo\": 1,\n" +
                "                \"totalNumberOfSingleBattery\": 24,\n" +
                "                \"singleBatteryNum\": 24,\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 5,\n" +
                "                \"rechargeEnergyStorageDeviceVol\": 65535,\n" +
                "                \"singleBatteryVolList\": [\n" +
                "                    3342,\n" +
                "                    3344,\n" +
                "                    3344,\n" +
                "                    3344,\n" +
                "                    3343,\n" +
                "                    3344,\n" +
                "                    3344,\n" +
                "                    3344,\n" +
                "                    3342,\n" +
                "                    3343,\n" +
                "                    3343,\n" +
                "                    3340,\n" +
                "                    3342,\n" +
                "                    3344,\n" +
                "                    3343,\n" +
                "                    3343,\n" +
                "                    3343,\n" +
                "                    3344,\n" +
                "                    3344,\n" +
                "                    3343,\n" +
                "                    3341,\n" +
                "                    3342,\n" +
                "                    3342,\n" +
                "                    3340\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageDeviceCur\": 65535,\n" +
                "                \"startBatteryNo\": 1,\n" +
                "                \"totalNumberOfSingleBattery\": 24,\n" +
                "                \"singleBatteryNum\": 24,\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 6,\n" +
                "                \"rechargeEnergyStorageDeviceVol\": 65535,\n" +
                "                \"singleBatteryVolList\": [\n" +
                "                    3340,\n" +
                "                    3340,\n" +
                "                    3340,\n" +
                "                    3340,\n" +
                "                    3342,\n" +
                "                    3341,\n" +
                "                    3342,\n" +
                "                    3342,\n" +
                "                    3339,\n" +
                "                    3340,\n" +
                "                    3340,\n" +
                "                    3338,\n" +
                "                    3339,\n" +
                "                    3342,\n" +
                "                    3342,\n" +
                "                    3342,\n" +
                "                    3340,\n" +
                "                    3342,\n" +
                "                    3342,\n" +
                "                    3342,\n" +
                "                    3338,\n" +
                "                    3339,\n" +
                "                    3340,\n" +
                "                    3339\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageDeviceCur\": 65535,\n" +
                "                \"startBatteryNo\": 1,\n" +
                "                \"totalNumberOfSingleBattery\": 24,\n" +
                "                \"singleBatteryNum\": 24,\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 7,\n" +
                "                \"rechargeEnergyStorageDeviceVol\": 65535,\n" +
                "                \"singleBatteryVolList\": [\n" +
                "                    3340,\n" +
                "                    3341,\n" +
                "                    3342,\n" +
                "                    3342,\n" +
                "                    3341,\n" +
                "                    3342,\n" +
                "                    3343,\n" +
                "                    3343,\n" +
                "                    3340,\n" +
                "                    3340,\n" +
                "                    3341,\n" +
                "                    3340,\n" +
                "                    3340,\n" +
                "                    3341,\n" +
                "                    3342,\n" +
                "                    3342,\n" +
                "                    3341,\n" +
                "                    3342,\n" +
                "                    3342,\n" +
                "                    3342,\n" +
                "                    3343,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3338\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageDeviceCur\": 65535,\n" +
                "                \"startBatteryNo\": 1,\n" +
                "                \"totalNumberOfSingleBattery\": 24,\n" +
                "                \"singleBatteryNum\": 24,\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 8,\n" +
                "                \"rechargeEnergyStorageDeviceVol\": 65535,\n" +
                "                \"singleBatteryVolList\": [\n" +
                "                    3340,\n" +
                "                    3339,\n" +
                "                    3340,\n" +
                "                    3339,\n" +
                "                    3341,\n" +
                "                    3339,\n" +
                "                    3340,\n" +
                "                    3340,\n" +
                "                    3339,\n" +
                "                    3338,\n" +
                "                    3339,\n" +
                "                    3337,\n" +
                "                    3338,\n" +
                "                    3339,\n" +
                "                    3340,\n" +
                "                    3340,\n" +
                "                    3341,\n" +
                "                    3340,\n" +
                "                    3340,\n" +
                "                    3340,\n" +
                "                    3340,\n" +
                "                    3338,\n" +
                "                    3338,\n" +
                "                    3338\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageDeviceCur\": 65535,\n" +
                "                \"startBatteryNo\": 1,\n" +
                "                \"totalNumberOfSingleBattery\": 24,\n" +
                "                \"singleBatteryNum\": 24,\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 9,\n" +
                "                \"rechargeEnergyStorageDeviceVol\": 65535,\n" +
                "                \"singleBatteryVolList\": [\n" +
                "                    3340,\n" +
                "                    3340,\n" +
                "                    3340,\n" +
                "                    3340,\n" +
                "                    3341,\n" +
                "                    3341,\n" +
                "                    3340,\n" +
                "                    3341,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3337,\n" +
                "                    3338,\n" +
                "                    3338,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3338,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3337,\n" +
                "                    3336,\n" +
                "                    3336,\n" +
                "                    3336\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageDeviceCur\": 65535,\n" +
                "                \"startBatteryNo\": 1,\n" +
                "                \"totalNumberOfSingleBattery\": 24,\n" +
                "                \"singleBatteryNum\": 24,\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 10,\n" +
                "                \"rechargeEnergyStorageDeviceVol\": 65535,\n" +
                "                \"singleBatteryVolList\": [\n" +
                "                    3338,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3337,\n" +
                "                    3337,\n" +
                "                    3337,\n" +
                "                    3336,\n" +
                "                    3338,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3338,\n" +
                "                    3338,\n" +
                "                    3338,\n" +
                "                    3337\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageDeviceCur\": 65535,\n" +
                "                \"startBatteryNo\": 1,\n" +
                "                \"totalNumberOfSingleBattery\": 24,\n" +
                "                \"singleBatteryNum\": 24,\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 11,\n" +
                "                \"rechargeEnergyStorageDeviceVol\": 65535,\n" +
                "                \"singleBatteryVolList\": [\n" +
                "                    3337,\n" +
                "                    3339,\n" +
                "                    3339,\n" +
                "                    3338,\n" +
                "                    3338,\n" +
                "                    3339,\n" +
                "                    3337,\n" +
                "                    3338,\n" +
                "                    3336,\n" +
                "                    3337,\n" +
                "                    3336,\n" +
                "                    3335,\n" +
                "                    3336,\n" +
                "                    3338,\n" +
                "                    3337,\n" +
                "                    3337,\n" +
                "                    3337,\n" +
                "                    3338,\n" +
                "                    3338,\n" +
                "                    3337,\n" +
                "                    3337,\n" +
                "                    3337,\n" +
                "                    3336,\n" +
                "                    3336\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageDeviceCur\": 65535,\n" +
                "                \"startBatteryNo\": 1,\n" +
                "                \"totalNumberOfSingleBattery\": 24,\n" +
                "                \"singleBatteryNum\": 24,\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 12,\n" +
                "                \"rechargeEnergyStorageDeviceVol\": 65535,\n" +
                "                \"singleBatteryVolList\": [\n" +
                "                    3337,\n" +
                "                    3338,\n" +
                "                    3338,\n" +
                "                    3338,\n" +
                "                    3338,\n" +
                "                    3338,\n" +
                "                    3338,\n" +
                "                    3337,\n" +
                "                    3336,\n" +
                "                    3336,\n" +
                "                    3336,\n" +
                "                    3335,\n" +
                "                    3337,\n" +
                "                    3337,\n" +
                "                    3338,\n" +
                "                    3337,\n" +
                "                    3337,\n" +
                "                    3338,\n" +
                "                    3336,\n" +
                "                    3336,\n" +
                "                    3335,\n" +
                "                    3335,\n" +
                "                    3335,\n" +
                "                    3335\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageDeviceCur\": 65535,\n" +
                "                \"startBatteryNo\": 1,\n" +
                "                \"totalNumberOfSingleBattery\": 24,\n" +
                "                \"singleBatteryNum\": 24,\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 13,\n" +
                "                \"rechargeEnergyStorageDeviceVol\": 65535,\n" +
                "                \"singleBatteryVolList\": [\n" +
                "                    3334,\n" +
                "                    3335,\n" +
                "                    3335,\n" +
                "                    3335,\n" +
                "                    3334,\n" +
                "                    3335,\n" +
                "                    3335,\n" +
                "                    3335,\n" +
                "                    3333,\n" +
                "                    3334,\n" +
                "                    3334,\n" +
                "                    3333,\n" +
                "                    3334,\n" +
                "                    3335,\n" +
                "                    3335,\n" +
                "                    3335,\n" +
                "                    3335,\n" +
                "                    3335,\n" +
                "                    3335,\n" +
                "                    3335,\n" +
                "                    3333,\n" +
                "                    3333,\n" +
                "                    3333,\n" +
                "                    3332\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageDeviceCur\": 65535,\n" +
                "                \"startBatteryNo\": 1,\n" +
                "                \"totalNumberOfSingleBattery\": 24,\n" +
                "                \"singleBatteryNum\": 24,\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 14,\n" +
                "                \"rechargeEnergyStorageDeviceVol\": 65535,\n" +
                "                \"singleBatteryVolList\": [\n" +
                "                    3332,\n" +
                "                    3334,\n" +
                "                    3334,\n" +
                "                    3334,\n" +
                "                    3333,\n" +
                "                    3334,\n" +
                "                    3333,\n" +
                "                    3334,\n" +
                "                    3331,\n" +
                "                    3331,\n" +
                "                    3331,\n" +
                "                    3330,\n" +
                "                    3324,\n" +
                "                    3325,\n" +
                "                    3325,\n" +
                "                    3325,\n" +
                "                    3325,\n" +
                "                    3325,\n" +
                "                    3325,\n" +
                "                    3325,\n" +
                "                    3323,\n" +
                "                    3323,\n" +
                "                    3323,\n" +
                "                    3325\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageDeviceCur\": 65535,\n" +
                "                \"startBatteryNo\": 1,\n" +
                "                \"totalNumberOfSingleBattery\": 24,\n" +
                "                \"singleBatteryNum\": 24,\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 15,\n" +
                "                \"rechargeEnergyStorageDeviceVol\": 65535,\n" +
                "                \"singleBatteryVolList\": [\n" +
                "                    3319,\n" +
                "                    3320,\n" +
                "                    3320,\n" +
                "                    3367,\n" +
                "                    3363,\n" +
                "                    3364,\n" +
                "                    3364,\n" +
                "                    3364,\n" +
                "                    3362,\n" +
                "                    3364,\n" +
                "                    3362,\n" +
                "                    3360,\n" +
                "                    3361,\n" +
                "                    3365,\n" +
                "                    3363,\n" +
                "                    3362,\n" +
                "                    3364,\n" +
                "                    3365,\n" +
                "                    3364,\n" +
                "                    3362,\n" +
                "                    3364,\n" +
                "                    3363,\n" +
                "                    3362,\n" +
                "                    3360\n" +
                "                ]\n" +
                "            },\n" +
                "            {\n" +
                "                \"rechargeEnergyStorageDeviceCur\": 65535,\n" +
                "                \"startBatteryNo\": 1,\n" +
                "                \"totalNumberOfSingleBattery\": 24,\n" +
                "                \"singleBatteryNum\": 24,\n" +
                "                \"rechargeEnergyStorageSubsystemNo\": 16,\n" +
                "                \"rechargeEnergyStorageDeviceVol\": 65535,\n" +
                "                \"singleBatteryVolList\": [\n" +
                "                    3363,\n" +
                "                    3363,\n" +
                "                    3362,\n" +
                "                    3362,\n" +
                "                    3364,\n" +
                "                    3363,\n" +
                "                    3362,\n" +
                "                    3362,\n" +
                "                    3362,\n" +
                "                    3362,\n" +
                "                    3360,\n" +
                "                    3358,\n" +
                "                    3361,\n" +
                "                    3363,\n" +
                "                    3363,\n" +
                "                    3361,\n" +
                "                    3365,\n" +
                "                    3363,\n" +
                "                    3363,\n" +
                "                    3362,\n" +
                "                    3363,\n" +
                "                    3358,\n" +
                "                    3360,\n" +
                "                    3358\n" +
                "                ]\n" +
                "            }\n" +
                "        ],\n" +
                "        \"rechargeEnergyStorageSubsystemNum\": 16\n" +
                "    },\n" +
                "    \"replyOrNot\": 1,\n" +
                "    \"msgId\": \"11956223\",\n" +
                "    \"vehicleInfoAdd\": {\n" +
                "        \"altitude\": 0,\n" +
                "        \"ZAxisAngularVelocity\": 0,\n" +
                "        \"batteryGroupState\": 255,\n" +
                "        \"totalPlugInChargingCapacity\": 22008,\n" +
                "        \"batteryCode\": \"" + batteryCode + "\",\n" +
                "        \"wakenbysta\": 0,\n" +
                "        \"wakenbykey\": 1,\n" +
                "        \"GPS\": 50,\n" +
                "        \"faultLevel\": 255,\n" +
                "        \"XAxisAcceleration\": 0,\n" +
                "        \"totalKineticEnergyFeedBackPower\": 8101,\n" +
                "        \"smallBatteryVol\": 270,\n" +
                "        \"airConditionerTemperature\": 0,\n" +
                "        \"load\": 0,\n" +
                "        \"airConditionerState\": 0,\n" +
                "        \"wakenbycan\": 0,\n" +
                "        \"vin\": \"" + vin + "\",\n" +
                "        \"YAxisAcceleration\": 0,\n" +
                "        \"totalExchangeChargingCapacity\": 51,\n" +
                "        \"totalDischarge\": 26367,\n" +
                "        \"batteryCodeLength\": 12,\n" +
                "        \"powerBatteryWarning\": 0,\n" +
                "        \"batteryManufactor\": 7,\n" +
                "        \"wakenbygun\": 0,\n" +
                "        \"ZAxisAcceleration\": 9,\n" +
                "        \"pitchAngle\": 0,\n" +
                "        \"horizontalHeadingAngle\": 0,\n" +
                "        \"totalCharge\": 30161,\n" +
                "        \"rechargeMileage\": 65535,\n" +
                "        \"GPSState\": 0,\n" +
                "        \"wakenbyrtc\": 0,\n" +
                "        \"YAxisAngularVelocity\": 0,\n" +
                "        \"XAxisAngularVelocity\": 0\n" +
                "    },\n" +
                "    \"vehicle\": {\n" +
                "        \"CSQ\": 23,\n" +
                "        \"chargeState\": 3,\n" +
                "        \"workMode\": 255,\n" +
                "        \"SOC\": 84,\n" +
                "        \"insulationResistance\": 65535,\n" +
                "        \"totalCur\": 11188,\n" +
                "        \"DC_DCState\": 1,\n" +
                "        \"speed\": 90,\n" +
                "        \"nhBattery\": 4361,\n" +
                "        \"accumulatedMileage\": 9780,\n" +
                "        \"totalVol\": 6363,\n" +
                "        \"vehicleState\": 1,\n" +
                "        \"gear\": 14\n" +
                "    },\n" +
                "    \"realTimeExtendedData\": {\n" +
                "        \"mainNegativeRelayStatus\": 2,\n" +
                "        \"cellAvgVol\": 3323,\n" +
                "        \"mainNegativeRelayAdhesionFault\": 0,\n" +
                "        \"chargingRelay2AdhesionFault\": 0,\n" +
                "        \"cellAvgTemperature\": 75,\n" +
                "        \"attachmentRelayAdhesionFault\": 0,\n" +
                "        \"BMSBalanceStatus\": 0,\n" +
                "        \"batteryPackNagativeInsulationVaule\": 6602,\n" +
                "        \"mainNegativeRelayUnableCloseAlarm\": 0,\n" +
                "        \"DCChargeTwoPositiveRelayUnClosedAlarm\": 0,\n" +
                "        \"overDischargeCurAlarm\": 0,\n" +
                "        \"packagePackProtectAlarm\": 0,\n" +
                "        \"prechargeRelayStatus\": 1,\n" +
                "        \"DCChargeOnePositiveRelayUnClosedAlarm\": 0,\n" +
                "        \"attachmentRelayStatus\": 0,\n" +
                "        \"branchExcessiveDifferentialPressureAlarm\": 0,\n" +
                "        \"chargeNegativeRelay1Status\": 1,\n" +
                "        \"thermalManagementSystemFault\": 0,\n" +
                "        \"heatingFilmOrTMSUnableconnectAlarm\": 0,\n" +
                "        \"mainPositiveRelayAdhesionFault\": 0,\n" +
                "        \"mainPositiveRelayStatus\": 2,\n" +
                "        \"heatingTwoRelayAdhesionFault\": 0,\n" +
                "        \"chargeNegativeRelay1AdhesionFault\": 0,\n" +
                "        \"chargingRelay2Status\": 1,\n" +
                "        \"BMSHardwareAlarm\": 0,\n" +
                "        \"smokeAlarm\": 0,\n" +
                "        \"heatingFilmOrTMSUnablecloseAlarm\": 0,\n" +
                "        \"rechargeableDeviceSN\": 1,\n" +
                "        \"BMSInternalCommunicationFault\": 0,\n" +
                "        \"batteryPackMaxDischargeCur\": 8000,\n" +
                "        \"branchCircuitBreakFault\": 0,\n" +
                "        \"batterLowTemperatureAlarm\": 0,\n" +
                "        \"faultNum\": 0,\n" +
                "        \"chargingRelay1AdhesionFault\": 0,\n" +
                "        \"chargingRelay1Status\": 1,\n" +
                "        \"mainPositiveRelayUnableCloseAlarm\": 0,\n" +
                "        \"batteryPackSOH\": 250,\n" +
                "        \"singleMaxVol\": 36,\n" +
                "        \"BMSStatus\": 2,\n" +
                "        \"DCChargeOneNagativeRelayUnClosedAlarm\": 0,\n" +
                "        \"poweredBy24VBMSAlarm\": 0,\n" +
                "        \"batteryHighVol\": 6363,\n" +
                "        \"batteryPackPositiveInsulationVaule\": 14581,\n" +
                "        \"chargeSocketOverTemperatureAlarm\": 0,\n" +
                "        \"singleCharge\": 181,\n" +
                "        \"chargeNegativeRelay2StatusAdhesionFault\": 0,\n" +
                "        \"DCChargeTwoNagativeRelayUnClosedAlarm\": 0,\n" +
                "        \"batteryPackMaxRechargeCur\": 8000,\n" +
                "        \"chargeAndNegativeRelay2Status\": 1,\n" +
                "        \"singleMinVol\": 25,\n" +
                "        \"chargeMode\": 0,\n" +
                "        \"recycleCurrentBeyondLimitFault\": 0,\n" +
                "        \"overChargeCurAlarm\": 0,\n" +
                "        \"chargeGunConnectStatus\": 0,\n" +
                "        \"fireAlarm\": 0,\n" +
                "        \"heatingOneRelayAdhesionFault\": 0\n" +
                "    },\n" +
                "    \"batteryPackAmbientTemperature\": 255,\n" +
                "    \"batteryAlarmInfo\": {\n" +
                "        \"vehicleStorageEnergyDeviceUnderVolAlarm\": 0,\n" +
                "        \"highTemperatureBatteryAlarm\": 0,\n" +
                "        \"highestAlarmLevel\": 0,\n" +
                "        \"jumpSOCAlarm\": 0,\n" +
                "        \"singleBatteryOvervolAlarm\": 0,\n" +
                "        \"differentTemperatureAlarm\": 0,\n" +
                "        \"highVolInterlockStatusAlarm\": 0,\n" +
                "        \"lowSOCAlarm\": 0,\n" +
                "        \"vehicleStorageEnergyDeviceOverVolAlarm\": 0,\n" +
                "        \"insulationAlarm\": 0,\n" +
                "        \"highSOCAlarm\": 0,\n" +
                "        \"rechargeEnergyStorageSubsystemNotMatchAlarm\": 0,\n" +
                "        \"singleBatteryPoorConsistencyAlarm\": 0,\n" +
                "        \"singleBatteryUnderVolAlarm\": 0\n" +
                "    },\n" +
                "    \"iccid\": \"" + externalCode + "\",\n" +
                "    \"dataTime\": \"" + dateFormat.format(date) + "\",\n" +
                "    \"dataNo\": 1337,\n" +
                "    \"sn\": \"" + externalCode + "\",\n" +
                "    \"extremum\": {\n" +
                "        \"minVolBatteryCellCode\": 11,\n" +
                "        \"maxTemperatureProbeSerialNumber\": 6,\n" +
                "        \"maxTemperatureVal\": 67,\n" +
                "        \"minTemperatureVal\": 64,\n" +
                "        \"minBatteryCellVol\": 3325,\n" +
                "        \"maxTemperatureSubsystemNum\": 4,\n" +
                "        \"maxVolBatterySubsystemNum\": 7,\n" +
                "        \"minTemperatureProbeSerialNumber\": 3,\n" +
                "        \"maxVolBatteryCellCode\": 7,\n" +
                "        \"minVolBatterySubsystemNum\": 2,\n" +
                "        \"minTemperatureSubsystemNum\": 2,\n" +
                "        \"maxBatteryCellVol\": 3338\n" +
                "    },\n" +
                "    \"timestamp\": \"" + dateFormat.format(date) + "\"\n" +
                "}";


        sendMQTT(env, pubTopic, content,batteryCode);

    }
    public static Boolean sendMQTT(String env, String pubTopic, String content, String clients) {
        try {
            int qos = 2;
            String broker = "";
            if (env.equals("UAT")) {
                broker = "tcp://10.4.6.74:12883";
            } else if (env.equals("FAT")) {
                broker = "tcp://10.5.6.74:1883";
            } else if (env.equals("DEV")) {
                broker = "tcp://10.6.6.72:1883";
            } else if (env.equals("HG")) {
                broker = "tcp://10.9.25.100:1883";
            }
            String clientId = "mqttx_test" + clients;
            MemoryPersistence persistence = new MemoryPersistence();
            MqttClient client = new MqttClient(broker, clientId, persistence);

            // MQTT 连接选项
            MqttConnectOptions connOpts = new MqttConnectOptions();
            connOpts.setUserName("admin");
            connOpts.setPassword("veZgHjmY".toCharArray());

            if (env.equals("HG")) {
                connOpts.setUserName("admin");
                connOpts.setPassword("rhdk@2024".toCharArray());
            }else{
                connOpts.setUserName("admin");
                connOpts.setPassword("veZgHjmY".toCharArray());
            }
            // 保留会话
            connOpts.setCleanSession(true);

            // 设置回调
            client.setCallback(new PushCallback());

            // 建立连接
            System.out.println("Connecting to broker: " + broker);
            client.connect(connOpts);

            System.out.println("Connected");
            System.out.println("Topic: " + pubTopic);
            System.out.println("Publishing message: " + content);

            // 订阅
            //client.subscribe(subTopic);

            // 消息发布所需参数
            MqttMessage message = new MqttMessage(content.getBytes());
            message.setQos(qos);
            client.publish(pubTopic, message);
            System.out.println("Message published");

            client.disconnect();
            System.out.println("Disconnected");
            client.close();
        } catch (MqttException me) {
            System.out.println("reason " + me.getReasonCode());
            System.out.println("msg " + me.getMessage());
            System.out.println("loc " + me.getLocalizedMessage());
            System.out.println("cause " + me.getCause());
            System.out.println("excep " + me);
            me.printStackTrace();
            return false;
        }
        return true;
    }
}
